# Copyright (c) 2024, CAS Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from frappe import _
import frappe
from frappe.model.document import Document

class ProfitLossConfigCN(Document):
    def validate(self):
        # 校验配置项唯一性（同一账户在同一模板中只能配置一次）
        accounts = []
        for item in self.items:
            if item.account in accounts:
                frappe.throw(_(f"Account {item.account} is duplicated in config items"))
            accounts.append(item.account)
        
        # 校验排序ID唯一性
#        sort_ids = []
#        for item in self.items:
#            if item.sort_id in sort_ids:
#                frappe.throw(_(f"Sort ID {item.sort_id} is duplicated in config items"))
#            sort_ids.append(item.sort_id)